{include file="public/header"}
{load href="/public/static/Content/ThemesBusiness/ListPage.css"}
<script src="/public/static/Scripts/common-binder-list-view.js"></script>
<script src="/public/static/Scripts/ScriptsEasyui/datagrid-filter.js"></script>

<script type="text/javascript">

    var data = null;
    var gridListHandler = new listGridHandler(data, 'gridListHandler', 'gridList');
    gridListHandler.formName = '商品广告';
    gridListHandler.enableFilter = false;
    $(function () {
        gridListHandler.bindFilter($('#gridList'));
    });
    gridListHandler.getNewUrl = function (id) {
        return '/admin/banner/add';
    };
    /* gridListHandler.getEditUrl = function(recordID) {
         return '/admin/usergroup/edit/' + recordID;
     };*/

    gridListHandler.getDeleteUrl = function (recordID) {
        return '/admin/banner/del/' + recordID;

    };
    // function formatState(val, row, index) {
    //     if (row.status == 0) {
    //         val = '<span style="display:inline-block;background-color:#abbac3;color:#fff;padding:1px 5px;">' +
    //             '正常' +
    //             '</span>';
    //     }
    //     else {
    //         val = '<span style="display:inline-block;background-color:#d15b47;color:#fff;padding:1px 5px;">' +
    //             '停用' +
    //             '</span>';
    //     }
    //     return val;
    // }

    function EditRecord(id) {
        //alert(id);return;
        if (id <= 0) {
            $.messager.alert('提示', "没有ID", 'info');
            return 0;
        } else {
            window.showBusinessForm("商品编辑", '/admin/banner/edit.html?id=' + id);
        }


    }

    function del(id) {
        if (id <= 0) {
            $.messager.alert('提示', "删除失败", 'info');
            return 0;
        }

        $.messager.confirm('删除确认', '确实要删除选中的记录？', function (r) {
            if (r) {
                $.ajax({
                    type: "POST",
                    url: 'del.html?id=' + id,
                })
                    .success(function (result) {
                        if (result.status > 0) {
                            $.messager.alert('提示', result.msg, "info");
                            window.location.reload();
                        } else {
                            $.messager.alert('提示', result.msg, "error");
                        }
                    })
                    .error(function (result) {
                        var message = "很抱歉，操作出现异常！请联系管理员。";
                        if (result) {
                            if (result.responseJSON && result.responseJSON.ExceptionMessage) {
                                message = result.responseJSON.ExceptionMessage;
                            }
                            else if (result.responseText) {
                                message = result.responseText;
                            }
                        }

                        $.messager.alert('错误', message.replace("-10", ""), 'error');
                    });
            }
        });

    }

    function formatImg(val, row, index) {

        val = '<img style="width:60px;" src="/uploads/banner/'+row.img+'" />';
        return val;
    }

    function formatAction(val, row, index) {

        val = '{eq name="power.edit" value="true"}<a href="#" style="float:left" title="编辑" onclick="EditRecord(' + row.id + ')"><div class="icon-page-edit"></div></a>{/eq}' +
            '{eq name="power.del" value="true"}<a href="#" style="float:left" title="删除" onclick="del(' + row.id + ')"><div class="icon-page-delete"></div></a>{/eq}';
        return val;
    }


</script>


<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" class="grid-toolbar-panel" id="gridList_ToolBar">
        {eq name="power.add" value="true"}
        <a href="#" id="news" onclick="gridListHandler.showNewDialog()" class="easyui-linkbutton grid-toolbar-button"
            data-options="iconCls:'icon-add'" title="新建">新建</a>
        {/eq}
    </div>
    <div data-options="region:'center',border:false">
        <table id="gridList" exusagetype="MultiSelection"
        data-options="pagination:true,pageSize:15,pageList:[10,15,20],multiSort:true,remoteSort:true,striped:true,fit:true,fitColumns:true,rownumbers:true,idField:'_ID',singleSelect: true"
            url="/admin/banner/index.html?ajax=1">
            <thead data-options="frozen:true">
                <tr>
                    <th data-options="field:'img',halign:'center',align:'left',width:150,formatter:formatImg"><span
                            class="grid-header-sortable">图片</span></th>
                    <th data-options="field:'sort',halign:'center',align:'left',width:150"><span
                            class="grid-header-sortable">排序</span></th>
                    <th data-options="field:'addtime',halign:'center',align:'left',width:150"><span
                            class="grid-header-sortable">添加时间</span></th>
                    <th data-options="field:'updatetime',halign:'center',align:'left',width:150"><span
                            class="grid-header-sortable">更新时间</span></th>
                    <th data-options="field:'id',width:100,halign:'center',align:'center',formatter:formatAction">操作
                    </th>
                </tr>
            </thead>

        </table>


    </div>
</div>
{include file="public/footer"/}